#include "key_IT.h"

void hal_gpio_IT_init(void)
{
    // 1. 使用GPIOF控制器的时钟
    RCC->MP_AHB4ENSETR = (0x1 << 5);
    // 2. 设置PF9引脚为输入的功能
    GPIOF->MODER &= (~(0x3 << 18));
}
// KEY1->PF9->EXTI9-->输入事件编号为：9
void hal_exti_IT_init(void)
{
    // 1. 设置PF9连接到EXTI9上   EXTI_EXTICR3[15:8] = 0x5
    EXTI->EXTICR3 &= (~(0xff << 8));
    EXTI->EXTICR3 |= (0x5 << 8);
    // 2. 设置KEY1按键为下降沿检测          EXTI_FTSR1[9] = 0x1
    EXTI->FTSR1 |= (0x1 << 9);
    // 3. 使能EXTI9中断                    EXTI_C1IMR1[9] = 0x1
    EXTI->C1IMR1 |= (0x1 << 9);
}
// KEY1->PF9->EXTI9-->中断号为99
void hal_gic_IT_init(void) 
{
    // 1. 设置GICD层的中断使能   GICD_ISENABLER3[3] = 0x1
    GICD->ISENABLER[3] |= (0x1 << 3);
    // 2. 设置GICD层的中断优先级   GICD_IPRIORITYR24[31:27] = 自己定义 范围0-31
    GICD->IPRIORITYR[24] &= (~(0x1f << 27));
    GICD->IPRIORITYR[24] |= (0x5 << 27);
    // 3. 设置GICD层中断目标分配   GICD_ITARGETSR24[25:24] = 0x1
    GICD->ITARGETSR[24] &= (~(0x3 << 24));
    GICD->ITARGETSR[24] |= (0x1 << 24);
    // 4. 设置GICD层全局中断使能   GICD_CTLR[0] = 0x1
    GICD->CTRL |= (0x1 << 0);
    // 5. 设置GICC层中断优先级屏蔽 GICC_PMR[7:3] = 0x1F  自己也可以给其他值
    GICC->PMR |= (0x1F << 3);
	// 6. 设置GICC层全局中断使能   GICC_CTLR[0] = 0x1
	GICC->CTRL |= (0x1 << 0);
}